package com.pethub.controller.web;

import java.io.Console;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.print.DocFlavor.STRING;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.plaf.metal.MetalIconFactory.PaletteCloseIcon;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.aspectj.weaver.ast.Var;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;





@Controller
@RequestMapping("/")
public class testController {

	/**
	 * 登录首页
	 * */
	@RequestMapping(value="/",method=RequestMethod.GET)
	public String home(ModelMap model) {
		return "firstPage";
	}
	
	
	/**
	 * 登录首页
	 * */
	
	@RequestMapping(value="/home",method=RequestMethod.GET)
	public String printnav2(ModelMap model) {
		return "loginHome";
	}
	/**
	 * 激活用户页
	 * */
	
	@RequestMapping(value="/activate/{id}",method=RequestMethod.GET)
	public String activate(ModelMap model,@PathVariable String id) {
		System.out.println("activate"+id);
		return "activate";
	}
	
	
	/**
	 * 用来添加药品信息
	 * **/
	@RequestMapping(value="/add-medicals/{id}",method=RequestMethod.GET)
	public ModelAndView addMedicals(Model model,@PathVariable String id,HttpSession httpSession) {
		System.out.println("add medical" + ((UserInfo)httpSession.getAttribute("user")).getName());
		ModelAndView modelAndView = new ModelAndView("addMedicals");
		modelAndView.addObject("petDetail", ((UserInfo)httpSession.getAttribute("user")).getPetDetail());
		modelAndView.addObject("changeType", null);
		return modelAndView;
	}
	
	/**
	 * 用来添加药品信息
	 * **/
	@RequestMapping(value="/log_off",method=RequestMethod.GET)
	public ModelAndView logOff(Model model,HttpSession httpSession) {
		System.out.println("ph_login");
		ModelAndView modelAndView = new ModelAndView("ph_login");
		httpSession.invalidate();
		modelAndView.addObject("UserInfo", new UserInfo());
		return modelAndView;
	}
	
	
	/**
	 * 用来说明过敏原添加完毕
	 * **/
	@RequestMapping(value="/detail-changed",method=RequestMethod.POST)
	public ModelAndView addedAllergy(Model model,@ModelAttribute(value="petDetail") petDetail petDetail,HttpSession httpSession) {
		System.out.println("added" + httpSession.getAttribute("changeType") + ((UserInfo)httpSession.getAttribute("user")).getName());
		ModelAndView modelAndView = new ModelAndView("petDetail");
		System.out.println(petDetail.getPetMedicalDosage());
		System.out.println(petDetail.getPetMedicalFrequency());
		System.out.println(petDetail.getPetMedicalTitle());
		String changeType = (String) httpSession.getAttribute("changeType");
		petDetail pD = (petDetail)((UserInfo)httpSession.getAttribute("user")).getPetDetail();
		switch (changeType) {
		case "medical":{pD.setPetMedicalTitle(petDetail.getPetMedicalTitle());pD.setPetMedicalPurpose(petDetail.getPetMedicalPurpose());pD.setPetMedicalFrequency(petDetail.getPetMedicalFrequency());pD.setPetMedicalDosage(petDetail.getPetMedicalDosage());pD.setPetMedicalVeterinary(petDetail.getPetMedicalVeterinary());pD.setPetMedicalOtherInfo(petDetail.getPetMedicalOtherInfo());break;}
		case "allergy":{pD.setPetAllergyTitle(petDetail.getPetAllergyOtherInfo());pD.setPetAllergyTreat(petDetail.getPetAllergyTreat());pD.setPetAllergyReact(petDetail.getPetAllergyReact());pD.setPetAllergyOtherInfo(petDetail.getPetAllergyOtherInfo());break;}
		case "condition":{pD.setPetConditionTitle(petDetail.getPetConditionTitle());pD.setPetConditionDiagnose(petDetail.getPetConditionDiagnose());pD.setPetConditionDiagnoseOtherInfo(petDetail.getPetConditionDiagnoseOtherInfo());break;}
		case "procedure":{pD.setPetProcedureTitle(petDetail.getPetProcedureTitle());pD.setPetProcedureInfo(petDetail.getPetProcedureInfo());pD.setPetProcedureResult(petDetail.getPetProcedureResult());pD.setPetProcedureReason(petDetail.getPetProcedureReason());pD.setPetProcedureOtherInfo(petDetail.getPetProcedureOtherInfo());;break;}
		case "vaccination":{pD.setPetVaccinationTitle(petDetail.getPetVaccinationTitle());pD.setPetVaccinationInfo(petDetail.getPetVaccinationInfo());pD.setPetVaccinationReason(petDetail.getPetVaccinationReason());pD.setPetVaccinationOtherInfo(petDetail.getPetVaccinationOtherInfo());break;}
		default:break;
		}
		((UserInfo)httpSession.getAttribute("user")).setPetDetail(pD);
		modelAndView.addObject("addedDetail", "更新成功");
		return modelAndView;
	}
	
	/**
	 * 宠物说明文档
	 * */
	@RequestMapping(value="/node/add/pet-record")
	public ModelAndView petRecord(Model model,HttpSession httpSession) {
		System.out.println("pet record");
		ModelAndView modelAndView = new ModelAndView("petRecord");
		modelAndView.addObject("petDetail", ((UserInfo)httpSession.getAttribute("user")).getPetDetail());
		return modelAndView;
	}

	/**
	 * 处理宠物记录更新完成
	 * */
	@RequestMapping(value="/node/add/pet-record-finished")
	public String petRecordFinished(Model model,HttpSession httpSession,@ModelAttribute(value="petDetail") petDetail	p) {
		System.out.println("pet record finished" + p.getPetRecordDescript()+p.getPetRecordTitle());
		return "loginHome";
	}
	
	/**
	 * 宠物丢失页面
	 * */
	@RequestMapping(value="/report-missing/{id}")
	public ModelAndView reportMissing(Model model,HttpSession httpSession) {
		System.out.println("report missing");
		ModelAndView modelAndView = new ModelAndView("reportMissing");
		modelAndView.addObject("UserInfo", httpSession.getAttribute("user"));
		modelAndView.addObject("petDetail", ((UserInfo)httpSession.getAttribute("user")).getPetDetail());
		return modelAndView;
	}


	/**
	 * 用来添加过敏信息
	 * **/
	@RequestMapping(value="/add-allergy/{id}",method=RequestMethod.GET)
	public ModelAndView addAllergy(Model model,@PathVariable String id,HttpSession httpSession) {
		System.out.println("add allergy" + ((UserInfo)httpSession.getAttribute("user")).getName());
		ModelAndView modelAndView = new ModelAndView("addAllergy");
		modelAndView.addObject("petDetail", ((UserInfo)httpSession.getAttribute("user")).getPetDetail());
		return modelAndView;
	}

	
	/**
	 * 用来添加动物详细状况
	 * **/
	@RequestMapping(value="/add-condition/{id}",method=RequestMethod.GET)
	public ModelAndView addCondition(Model model,@PathVariable String id,HttpSession httpSession) {
		System.out.println("add condition" + ((UserInfo)httpSession.getAttribute("user")).getName());
		ModelAndView modelAndView = new ModelAndView("addCondition");
		modelAndView.addObject("petDetail", ((UserInfo)httpSession.getAttribute("user")).getPetDetail());
		return modelAndView;
	}
	
	/**
	 * 用来添加动物详细状况
	 * **/
	@RequestMapping(value="/add-procedure/{id}",method=RequestMethod.GET)
	public ModelAndView addProcedure(Model model,@PathVariable String id,HttpSession httpSession) {
		System.out.println("add procedure" + ((UserInfo)httpSession.getAttribute("user")).getName());
		ModelAndView modelAndView = new ModelAndView("addProcedure");
		modelAndView.addObject("petDetail", ((UserInfo)httpSession.getAttribute("user")).getPetDetail());
		return modelAndView;
	}

	/**
	 * 用来添加动物详细状况
	 * **/
	@RequestMapping(value="/add-vaccination/{id}",method=RequestMethod.GET)
	public ModelAndView addVaccination(Model model,@PathVariable String id,HttpSession httpSession) {
		System.out.println("add vaccination" + ((UserInfo)httpSession.getAttribute("user")).getName());
		ModelAndView modelAndView = new ModelAndView("addVaccination");
		modelAndView.addObject("petDetail", ((UserInfo)httpSession.getAttribute("user")).getPetDetail());
		return modelAndView;
	}
	
	/**
	 * 提供宠物来源信息
	 * */
	@RequestMapping(value="/pet-providers/{id}",method=RequestMethod.GET)
	public ModelAndView petPriders(ModelMap model,@PathVariable String id) {
		System.out.println("pet-provider"+id);
		ModelAndView modelAndView = new ModelAndView("petProvider");
		model.addAttribute("id", id);
		return modelAndView;
	}
	
	/**
	 * 提供宠物用药信息
	 * */
	@RequestMapping(value="/pet-medical/{id}",method=RequestMethod.GET)
	public ModelAndView petMedicals(ModelMap model,@PathVariable String id,HttpSession httpSession) {
		System.out.println("pet-medical"+id);
		ModelAndView modelAndView = new ModelAndView("petDetail");
		model.addAttribute("id", id);
		modelAndView.addObject("petDetail", ((UserInfo)httpSession.getAttribute("user")).getPetDetail());
		return modelAndView;
	}
	/**
	 * 重新填写宠物详细信息
	 * 
	 * */
	@RequestMapping(value="/node/{id}",method=RequestMethod.GET)
	public ModelAndView nodes(ModelMap model,@PathVariable String id,HttpSession httpSession)
	{
		ModelAndView modelAndView = new ModelAndView("nodes");
		
		List<String> yearList = new ArrayList<String>();
		for(int year=2018;year>1900;year--) {
			yearList.add(String.valueOf(year));
		}
		List<String> monthList = new ArrayList<String>();
		for(int month=12;month>0;month--) {
			monthList.add(String.valueOf(month));
		}
		List<String> dayList = new ArrayList<String>();
		for(int day=31;day>0;day--) {
			dayList.add(String.valueOf(day));
		}
		
		List<String> countryList = new ArrayList<String>();
		List<String> provinceList = new ArrayList<String>();
		List<String> colorList = new ArrayList<String>();
		List<String> sizeList = new ArrayList<String>();
		List<String> tailList = new ArrayList<String>();
		List<String> speciesList = new ArrayList<String>();
		fileUpload fileUpload = new fileUpload();
		
		modelAndView.addObject("UserInfo", httpSession.getAttribute("user"));
		modelAndView.addObject("yearList", yearList);
		modelAndView.addObject("monthList", monthList);
		modelAndView.addObject("dayList", dayList);
		modelAndView.addObject("countryList", countryList);
		modelAndView.addObject("provinceList", provinceList);
		modelAndView.addObject("colorList", colorList);
		modelAndView.addObject("sizeList", sizeList);
		modelAndView.addObject("tailList", tailList);
		modelAndView.addObject("speciesList", speciesList);
		modelAndView.addObject("fileUpload",fileUpload);
		
		
		return modelAndView;
	}
	
	
	/**
	 * 用户信息填写玩成功保存数据功能
	 * userInfo是用户类
	 * */
	@RequestMapping(value="/nodes/finished",method=RequestMethod.POST)
	public String nodes_finish(ModelMap model,@ModelAttribute(value="UserInfo") UserInfo u) {
		
		System.out.println("registration finish");
		System.out.println(u.getBirthDay());
		System.out.println(u.getCity());
		return "sRegistration";
	}
	
	/**
	 * 已经存在用户页
	 * */
	
	@RequestMapping(value="/activate/existing-user",method=RequestMethod.GET)
	public String activateExisting(ModelMap model) {
		return "existing_user";
	}
	

	/**
	 * 
	 * 标签页
	 * 
	 * 进入标签页，返回标签类
	 * 
	 * **/
	@RequestMapping(value="/tag",method=RequestMethod.GET)
	public ModelAndView tag(ModelMap model) {
		ModelAndView modelAndView = new ModelAndView("tag");
		modelAndView.addObject("tag",new tag());
		return modelAndView;
	}
	
	/**
	 * 标签检查
	 * tag是一个标签类
	 * 
	 * */
	
	@RequestMapping(value="/tag_check",method=RequestMethod.POST)
	public String tag_check(ModelMap model,@ModelAttribute(value="tag") tag tg) {
		System.out.println("tag ID");
		System.out.println(tg.getTagID());
		return "tag";
	}
	
	/***
	 * 
	 * 登录首页，返回用户类
	 * 
	 * 
	 * */
	
	@RequestMapping(value="/ph_login",method=RequestMethod.GET)
	public ModelAndView ph_login(ModelMap model) {
		System.out.println("ph_login");
		ModelAndView modelAndView = new ModelAndView("ph_login");
		modelAndView.addObject("UserInfo", new UserInfo());
		return modelAndView;
	}

	/**
	 * 登录信息检查
	 * userinfo是用户类
	 * */
	@RequestMapping(value="/ph_login_check",method=RequestMethod.POST)
	public String ph_login_check(ModelMap model,@ModelAttribute(value="UserInfo") UserInfo u,HttpSession httpSession) {
		System.out.println("destination=ph_login");
		System.out.println(u.getEmail());
		System.out.println(u.getPassword());
		UserInfo userInfo = new UserInfo();
		httpSession.setAttribute("item", "10");
		httpSession.setAttribute("price", "20");
		httpSession.setAttribute("username", "tom");
		httpSession.setAttribute("user", userInfo);
		return "loginHome";
	}
	
	/**
	 * 注册页，返回保存用户信息类
	 * yearList年份列表
	 * MonthList月份列表
	 * dayList日期列表
	 * countryList国家列表
	 * provinceList省份列表
	 * colorList宠物颜色列表
	 * coatList宠物毛发列表
	 * sizeList宠物大小列表
	 * tailList宠物尾巴类型
	 * speciesList宠物种类
	 * fileUpload用于传递文件对象
	 * 
	 * */
	@RequestMapping(value="/registration",method=RequestMethod.GET)
	public ModelAndView registration1(ModelMap model) {
		System.out.println("registration");
		ModelAndView modelAndView = new ModelAndView("register");
		
		List<String> yearList = new ArrayList<String>();
		for(int year=2018;year>1900;year--) {
			yearList.add(String.valueOf(year));
		}
		List<String> monthList = new ArrayList<String>();
		for(int month=12;month>0;month--) {
			monthList.add(String.valueOf(month));
		}
		List<String> dayList = new ArrayList<String>();
		for(int day=31;day>0;day--) {
			dayList.add(String.valueOf(day));
		}
		
		List<String> countryList = new ArrayList<String>();
		List<String> provinceList = new ArrayList<String>();
		List<String> colorList = new ArrayList<String>();
		List<String> sizeList = new ArrayList<String>();
		List<String> tailList = new ArrayList<String>();
		List<String> speciesList = new ArrayList<String>();
		fileUpload fileUpload = new fileUpload();
		
		modelAndView.addObject("UserInfo", new UserInfo());
		modelAndView.addObject("yearList", yearList);
		modelAndView.addObject("monthList", monthList);
		modelAndView.addObject("dayList", dayList);
		modelAndView.addObject("countryList", countryList);
		modelAndView.addObject("provinceList", provinceList);
		modelAndView.addObject("colorList", colorList);
		modelAndView.addObject("sizeList", sizeList);
		modelAndView.addObject("tailList", tailList);
		modelAndView.addObject("speciesList", speciesList);
		modelAndView.addObject("fileUpload",fileUpload);
		
		
		return modelAndView;
	}
	
	/**
	 * 用户信息填写玩成功保存数据功能
	 * userInfo是用户类
	 * */
	@RequestMapping(value="/registration_finish",method=RequestMethod.POST)
	public ModelAndView registration_finish(ModelMap model,@ModelAttribute(value="UserInfo") UserInfo u) {
		
		System.out.println("registration finish");
		System.out.println("ph_login");
		ModelAndView modelAndView = new ModelAndView("ph_login");
		modelAndView.addObject("UserInfo", new UserInfo());
		return modelAndView;
	}
 
    // 上传配置
    private static final int MEMORY_THRESHOLD   = 1024 * 1024 * 3;  // 3MB
    private static final int MAX_FILE_SIZE      = 1024 * 1024 * 40; // 40MB
    private static final int MAX_REQUEST_SIZE   = 1024 * 1024 * 50; // 50MB
	/**
	 * 文件上传确认
	 * */
    /**
     * 上传数据及保存文件
     */
    @RequestMapping(value="/fileUploadCheck",method=RequestMethod.POST)
    protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    	System.out.println("do post");
    	InputStream inputStream = null;
		  OutputStream outputStream = null;
        // 检测是否为多媒体上传
        if (!ServletFileUpload.isMultipartContent(request)) {
            // 如果不是则停止
            PrintWriter writer = response.getWriter();
            writer.println("Error: 表单必须包含 enctype=multipart/form-data");
            writer.flush();
            return;
        }
 
        // 配置上传参数
        DiskFileItemFactory factory = new DiskFileItemFactory();
        // 设置内存临界值 - 超过后将产生临时文件并存储于临时目录中
        factory.setSizeThreshold(MEMORY_THRESHOLD);
        // 设置临时存储目录
        factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
        ServletFileUpload upload = new ServletFileUpload(factory);
         
        // 设置最大文件上传值
        upload.setFileSizeMax(MAX_FILE_SIZE);
         
        // 设置最大请求值 (包含文件和表单数据)
        upload.setSizeMax(MAX_REQUEST_SIZE);
        
        // 中文处理
        upload.setHeaderEncoding("UTF-8"); 
    
        try {
            List<FileItem> formItems = upload.parseRequest(request);
 
            if (formItems != null && formItems.size() > 0) {
                // 迭代表单数据
                for (FileItem item : formItems) {
                    // 处理不在表单中的字段
                    if (!item.isFormField()) {
                        String fileName = new File(item.getName()).getName();
                        inputStream = item.getInputStream();
                       String filepath = "/statics/file";
                       String fileRealpath = request.getSession().getServletContext().getRealPath(filepath);
                       System.out.println(fileRealpath);
                       File fileSaveFile = new File(fileRealpath);
                       if(!fileSaveFile.exists()) {
                    	   fileSaveFile.mkdirs();
                       }
                       String fName = fileRealpath + "/new_" + fileName;
         			   File newFile = new File(fName);
         			   if (!newFile.exists()) {
         			    newFile.createNewFile();
         			   }
         			   outputStream = new FileOutputStream(newFile);
         			   int read = 0;
         			   byte[] bytes = new byte[1024];
         			 
         			   while ((read = inputStream.read(bytes)) != -1) {
         			    outputStream.write(bytes, 0, read);
         			   }
         			  outputStream.close();
         			  request.setAttribute("message",
                              "文件上传成功!");
                    }
                }
            }
        } catch (Exception ex) {
            request.setAttribute("message",
                    "错误信息: " + ex.getMessage());
        }
	}
	
	
	/*
	 * 文章页，返回文章主页
	 * 
	 * **/
	@RequestMapping(value="/article",method=RequestMethod.GET)
	public String article(ModelMap model) {
		System.out.println("article finish");
		return "Article";
	}
	/**
	 * 文章数据页
	 * page是获取文章的页数，每页按照每页可通过循环处理返回篇幅
	 * name表明要搜索的文章关键字
	 * 
	 * */
	@RequestMapping(value="/article_data",method=RequestMethod.POST)
	public @ResponseBody List<Articl> article_data(@RequestParam int page,@RequestParam String name) {
		System.out.println("article data finish " +page);
		System.out.println("name" +name);
		List<Articl> articls = new ArrayList<Articl>();
		for(int i=1;i<4;i++) {
			Articl articl = new Articl();
			articl.setContent("文章体" + i);
			articl.setImageUrl("/pethub/images/" + i + ".jpg");
			articl.setTitle("文章头" + i);
			articls.add(articl);
		}
		return articls;
	}
	
	@RequestMapping(value="/providerDetail/{id}",method=RequestMethod.POST)
	public String updateProvider(@RequestParam String provider,@PathVariable String id) {
		System.out.println("updateProvider" + id + " " + provider);
		return "loginHome";
	}
	/*
	 * 
	 * 商店主页
	 * **/
	
	@RequestMapping(value="/shop_home",method=RequestMethod.GET)
	public String shophome(ModelMap model) {
		System.out.println("shop_home finish");
		return "shop_home";
	}
	
	/**
	 * 
	 * 商店中最受欢迎页面
	 * */

	@RequestMapping(value="/catalog/01-best-sellers",method=RequestMethod.GET)
	public String catalogBestSellers(ModelMap model) {
		System.out.println("best Seller finish");
		return "bestSeller";
	}
	
	/**
	 * 最受欢迎进入商品详细页面，参数是商品ID
	 * 返回商品的图片、价格、详细信息的对象
	 * */

	@RequestMapping(value="/catalog/01-best-sellers/{itemID}",method=RequestMethod.GET)
	public String getBestSellerDetail(Model model,@PathVariable("itemID") String itemID){
		System.out.println(itemID);
		List<items> items = new ArrayList<items>();
		for(int i=1;i<10;i++) {
			items item = new items();
			for(int j=1;j<4;j++) {
				item.setItemID("items"+j);
				item.setDetailImageURL("/pethub/images/" + j + ".jpg");
			}
			item.setItemPrice(i+"元");
			item.setItemDescription("这是一个测试描述，如果超过则不显示");
			items.add(item);
		}
		model.addAttribute("item", items);
		return "itemDetail";
	}
	
	/**
	 * 商店中猫最喜欢
	 * */
	@RequestMapping(value="/catalog/02-cat-tastic",method=RequestMethod.GET)
	public String catalogCatTastic(ModelMap model) {
		System.out.println("cat tastic finish");
		return "catTaste";
	}

	/**
	 * 猫最喜欢进入商品详细页面，参数是商品ID
	 * 返回商品的图片、价格、详细信息的对象
	 * */

	@RequestMapping(value="/catalog/02-cat-tastic/{itemID}",method=RequestMethod.GET)
	public String getCatTasticDetail(Model model,@PathVariable("itemID") String itemID){
		System.out.println(itemID);
		List<items> items = new ArrayList<items>();
		for(int i=1;i<10;i++) {
			items item = new items();
			for(int j=1;j<4;j++) {
				item.setItemID("items"+j);
				item.setDetailImageURL("/pethub/images/" + j + ".jpg");
			}
			item.setItemPrice(i+"元");
			item.setItemDescription("这是一个测试描述，如果超过则不显示");
			items.add(item);
		}
		model.addAttribute("item", items);
		return "itemDetail";
	}
	
	
	/**
	 * 商店中经典
	 * */
	@RequestMapping(value="/catalog/03-classic",method=RequestMethod.GET)
	public String catalogClassic(ModelMap model) {
		System.out.println("Classic finish");
		return "classic";
	}

	/**
	 * 经典商品进入商品详细页面，参数是商品ID
	 * 返回商品的图片、价格、详细信息的对象
	 * */

	@RequestMapping(value="/catalog/03-classic/{itemID}",method=RequestMethod.GET)
	public String getClassicDetail(Model model,@PathVariable("itemID") String itemID){
		System.out.println(itemID);
		List<items> items = new ArrayList<items>();
		for(int i=1;i<10;i++) {
			items item = new items();
			for(int j=1;j<4;j++) {
				item.setItemID("items"+j);
				item.setDetailImageURL("/pethub/images/" + j + ".jpg");
			}
			item.setItemPrice(i+"元");
			item.setItemDescription("这是一个测试描述，如果超过则不显示");
			items.add(item);
		}
		model.addAttribute("item", items);
		return "itemDetail";
	}
	
	/**
	 * 商店中经典
	 * */
	@RequestMapping(value="/catalog/04-sassy-smart-assy",method=RequestMethod.GET)
	public String catalogSassySmart(ModelMap model) {
		System.out.println("sassySmart finish");
		return "sassySmart";
	}

	/**
	 * 经典商品进入商品详细页面，参数是商品ID
	 * 返回商品的图片、价格、详细信息的对象
	 * */

	@RequestMapping(value="/catalog/04-sassy-smart-assy/{itemID}",method=RequestMethod.GET)
	public String getSassySmartDetail(Model model,@PathVariable("itemID") String itemID){
		System.out.println(itemID);
		List<items> items = new ArrayList<items>();
		for(int i=1;i<10;i++) {
			items item = new items();
			for(int j=1;j<4;j++) {
				item.setItemID("items"+j);
				item.setDetailImageURL("/pethub/images/" + j + ".jpg");
			}
			item.setItemPrice(i+"元");
			item.setItemDescription("这是一个测试描述，如果超过则不显示");
			items.add(item);
		}
		return "itemDetail";
	}
	
	/*
	 * page 获取第几页数据
	 * sorttype 以什么类型排序：价格price，日期date，热度hots,名称name
	 * numerpage 一次获取多少条数据
	 * pagetype 哪一类数据 bestSeller catTaste classic sassySmart
	 * **/

	@RequestMapping(value="/sellData",method=RequestMethod.POST)
	public @ResponseBody List<items> article_data(@RequestParam int page,@RequestParam String sorttype,@RequestParam int numperpage,@RequestParam String pagetype) {
		System.out.println("article data finish " +page);
		System.out.println("sorttype " +sorttype + " numperpage " + numperpage + "  pagetype " + pagetype);
		List<items> items = new ArrayList<items>();
		for(int i=1;i<10;i++) {
			items item = new items();
			for(int j=1;j<4;j++) {
				item.setItemID("items"+j);
				item.setDetailImageURL("/pethub/images/" + j + ".jpg");
			}
			item.setItemPrice(i+"元");
			item.setItemDescription("这是一个测试描述，如果超过则不显示");
			items.add(item);
		}
		return items;
	}
	
	@RequestMapping(value="/submitCart",method=RequestMethod.POST)
	public String submitCart(Model model,int price){
		System.out.println(price);
		model.addAttribute("price", price);
		return "pay/petPay";
	}
	
	@RequestMapping(value="/petClose",method=RequestMethod.GET)
	public String petClose(Model model) {
		String trade_no = "2018031121001004060200244445";
		String out_trade_no = "pethub2018-03-11+09%3A02%3A14";
		String operator_id = "张三";
		model.addAttribute("trade_no", trade_no);
		model.addAttribute("out_trade_no", out_trade_no);
		model.addAttribute("operator_id", operator_id);
		return "pay/petClose";
	}
	
	@RequestMapping(value="/petFastPayRefund",method=RequestMethod.GET)
	public String petFastPayRefund(Model model) {
		String trade_no = "2018031121001004060200244445";
		String out_trade_no = "pethub2018-03-11+09%3A02%3A14";
		model.addAttribute("trade_no", trade_no);
		model.addAttribute("out_trade_no", out_trade_no);
		System.out.println(trade_no);
		return "pay/petFastPayRefund";
	}
	
	@RequestMapping(value="/petQuery",method=RequestMethod.GET)
	public String petQuery(Model model) {
		String trade_no = "2018031121001004060200244445";
		String out_trade_no = "pethub2018-03-11+09%3A02%3A14";
		model.addAttribute("trade_no", trade_no);
		model.addAttribute("out_trade_no", out_trade_no);
		System.out.println(trade_no);
		return "pay/petQuery";
	}
	
	@RequestMapping(value="/petRefund",method=RequestMethod.GET)
	public String petRefund(Model model) {
		String trade_no = "2018031121001004060200244445";
		String out_trade_no = "pethub2018-03-11+09%3A02%3A14";
		String reason = "就是想退款，怎么着";
		int amount = 40;
		model.addAttribute("trade_no", trade_no);
		model.addAttribute("out_trade_no", out_trade_no);
		model.addAttribute("reason", reason);
		model.addAttribute("amount", amount);
		System.out.println(trade_no);
		return "pay/refund";
	}
	
//	提交订单返回参数total_amount=5.00&timestamp=2018-03-11+09%3A03%3A03&
//	sign=ZwTegq31lGh4kj4PUDNTAXEkn0fsB85Auf%2BrQDHHCkB7SL7eiE6l6CXyqEmFus6JHTZSC4LBcVpBqMt%2BbecEY6v3aOjtroxL2lCkg%2BR0qcj%2FYB%2F%2FG%2BrYnGTff1%2BJwEhHGW6BA2civra1E5YYZLzVpISQ0o9HzZTBotDw86ZpaAxh87YytFHgabhTszkTLKWWoJqnA6fQBgN6FKJgZtCav4nL9ORnSZK%2FwDNsfH%2B57nd2O7EyfR5f%2FTStN13fN5PkZlY2NWiQf1kM6ZsrXBrHxPNUfSB8zOWN3Tw5NYOpotygpV2AXf6SAUwS9nay2qjBwTmmTVgfwFq3WZ7CGP2rng%3D%3D
//	&trade_no=2018031121001004060200244445&sign_type=RSA2&auth_app_id=2016091100487891&charset=UTF-8&seller_id=2088102175176345&method=alipay.trade.page.pay.return&app_id=2016091100487891&out_trade_no=pethub2018-03-11+09%3A02%3A14&version=1.0
	@RequestMapping(value="/notifyUrl",method=RequestMethod.POST)
	public String payNotify(HttpServletRequest request,HttpServletResponse response) throws IOException {
		System.out.println("notify");
		return "pay/notify_url";
	}
	
//	提交订单返回参数返回参数total_amount=5.00&timestamp=2018-03-11+09%3A03%3A03&
//	sign=ZwTegq31lGh4kj4PUDNTAXEkn0fsB85Auf%2BrQDHHCkB7SL7eiE6l6CXyqEmFus6JHTZSC4LBcVpBqMt%2BbecEY6v3aOjtroxL2lCkg%2BR0qcj%2FYB%2F%2FG%2BrYnGTff1%2BJwEhHGW6BA2civra1E5YYZLzVpISQ0o9HzZTBotDw86ZpaAxh87YytFHgabhTszkTLKWWoJqnA6fQBgN6FKJgZtCav4nL9ORnSZK%2FwDNsfH%2B57nd2O7EyfR5f%2FTStN13fN5PkZlY2NWiQf1kM6ZsrXBrHxPNUfSB8zOWN3Tw5NYOpotygpV2AXf6SAUwS9nay2qjBwTmmTVgfwFq3WZ7CGP2rng%3D%3D
//	&trade_no=2018031121001004060200244445&sign_type=RSA2&auth_app_id=2016091100487891&charset=UTF-8&seller_id=2088102175176345&method=alipay.trade.page.pay.return&app_id=2016091100487891&out_trade_no=pethub2018-03-11+09%3A02%3A14&version=1.0
	@RequestMapping(value="/returnUrl",method=RequestMethod.POST)
	public String payReturn(HttpServletRequest request,HttpServletResponse response) throws IOException {
		System.out.println("return");
		return "pay/return_url";
	}
}
